<?php
/**
 *	  Copyright (c) 2011 http://www.ybanke.com All rights reserved.
 *	  This is NOT a freeware, use is subject to license terms
 *
 *        Ybanke 云班客电商返现系统
 *	  tel:0531-88909511
 */


class RebateController extends AdminBaseController {
	public function _initialize() {
		parent::_initialize();
		$this->db=M("user_rebate_log");
		$this->points_db=M("user_pointslog");
		$this->order_db = model('order');
		$this->user_db = model('user');
	}
	
	
	
	public function sellset() {
		if(IS_POST){
			M("user_sell_rebate_set")->where('id=1')->save($_POST);
		}
		$return_num=M("user")->sum("rebate_sell_num");
		$return_money=M("user_moneylog")->where("type=11")->sum("money");
		$map_today['sell_uid'] = array("neq",0);
		$amount_all = model('order')->where($map_today)->sum('real_amount');
		$amount_all=$amount_all==0?"0.00":$amount_all;
		$start=strtotime(date("Y/m/d", strtotime('-1 day'))." 00:00:01");
		$end=strtotime(date("Y/m/d", strtotime('-1 day'))." 23:59:59"); 
		$map_today['create_time'] =array('between',$start.','.$end);
		$map_today['sell_uid'] = array("neq",0);
		$amount_yesterday = model('order')->where($map_today)->sum('real_amount');
		$amount_yesterday=$amount_yesterday==0?"0.00":$amount_yesterday;

		$is_fafang_time=strtotime(date('Y-m-d 00:00:01',time()));
		$is_fafang=M("user_sell_rebate_log")->where("addtime>".$is_fafang_time)->count();
		$info=M("user_sell_rebate_set")->find();
		include $this->admin_tpl('Rebate/sellset');
	}
	
	public function sellyesterday() {
		$return_num=M("user")->sum("rebate_sell_num");
		$return_money=M("user_moneylog")->where("type=9 and msg='商家赠送发放'")->sum("money");
		$map_today['sell_uid'] = array("neq",0);
		$amount_all = model('order')->where($map_today)->sum('real_amount');
		$amount_all=$amount_all==0?"0.00":$amount_all;
		$start=strtotime(date("Y/m/d", strtotime('-1 day'))." 00:00:01");
		$end=strtotime(date("Y/m/d", strtotime('-1 day'))." 23:59:59"); 
		$map_today['create_time'] =array('between',$start.','.$end);
		$map_today['sell_uid'] = array("neq",0);
		$amount_yesterday = model('order')->where($map_today)->sum('real_amount');
		$amount_yesterday=$amount_yesterday==0?"0.00":$amount_yesterday;

		$is_fafang_time=strtotime(date('Y-m-d 00:00:01',time()));
		$is_fafang=M("user_sell_rebate_log")->where("addtime>".$is_fafang_time)->count();

		include $this->admin_tpl('Rebate/sellyesterday');
	}
	public function sellold() {
		if(IS_POST){
			$points_type=C("POINTS_TYPE");
			$sqlmap = array();
			$order = array();
			//排序
			$_order=isset($_POST['order']) ? ($_POST['order']) : NULL;
			$_sort=isset($_POST['sort']) ? ($_POST['sort']) : NULL;
			if($_order && $_sort){
				$order[$_sort] = $_order;
			}else{
				$order['id'] = 'desc';
			}
			
			if ($_GET['keyword']) {
				$map = array();
				$map['username'] = array('LIKE',"%".trim($_GET['keyword'])."%");
				$ids = model('user')->where($map)->getField('id',TRUE);
				$sqlmap['user_id'] = array('IN',$ids);
			}
			if($_GET["start"]!="" or $_GET["end"]!=""){
				$start = strtotime($_GET['start'].' 00:00:00');
				$end = strtotime($_GET['end'].' 23:59:59');
				$sqlmap['time'] =array('between',$start.','.$end);
			}
			$sqlmap['type'] =array('eq',3);
			$pagenum=isset($_POST['page']) ? intval($_POST['page']) : 1;
			$rowsnum=isset($_POST['rows']) && (int)($_POST['rows']) != 0 ? intval($_POST['rows']) : PAGE_SIZE;
			$data['total'] =M("user_pointslog")->where($sqlmap)->count();	//计算总数 
			$data['rows'] = M("user_pointslog")->where($sqlmap)->limit(($pagenum-1)*$rowsnum.','.$rowsnum)->order($order)->select();
			foreach ($data['rows'] as $key => $value) {
				$data['rows'][$key]['type'] = $points_type[$value["type"]];
				//$data['rows'][$key]['address'] = $value["province"].$value["city"].$value["hometown"].$value["address"];
				//$data['rows'][$key]['return_type']=$data['rows'][$key]['return_type']==1?"固定分红":"百分比分红";
				$data['rows'][$key]['username']=get_nickname($data['rows'][$key]['user_id']);
			}
			if (!$data['rows']) $data['rows']=array();
			echo json_encode($data);
		}else{
			include $this->admin_tpl('Rebate/sellold');
		}
	}
	public function sell_return_money() {

			showmessage('请使用自动发放');
			exit;
	

	}
	public function set() {
		if(IS_POST){
			M("user_rebate_set")->where('id=1')->save($_POST);
		}
		$return_num=M("user")->sum("rebate_num");
		$return_money=M("user_moneylog")->where("type=9 and msg='赠送发放'")->sum("money");
		$map_today['sell_uid'] = array("neq",0);
		$amount_all = model('order')->where($map_today)->sum('real_amount');
		$amount_all=$amount_all==0?"0.00":$amount_all;
		$start=strtotime(date("Y/m/d", strtotime('-1 day'))." 00:00:01");
		$end=strtotime(date("Y/m/d", strtotime('-1 day'))." 23:59:59"); 
		$map_today['create_time'] =array('between',$start.','.$end);
		$map_today['sell_uid'] = array("neq",0);
		$amount_yesterday = model('order')->where($map_today)->sum('real_amount');
		$amount_yesterday=$amount_yesterday==0?"0.00":$amount_yesterday;
		$info=M("user_rebate_set")->find();
		include $this->admin_tpl('Rebate/set');
	}
	/* 赠送权 */
	public function oldlist() {
		$map_today = array();
		$map=array();
		/* 今日销售情况 */
		$map_today['_string'] = "DATE_FORMAT(FROM_UNIXTIME(send_time),'%Y%m%d') = DATE_FORMAT(NOW(),'%Y%m%d')";
		$total_rebate = M("user_rebate_send_log")->field("sum(send_all_money) as total_rebate_money,send_user AS total_rebate")->where($map_today)->find();
		$map_today = array();
		$map_today['_string'] = "DATE_FORMAT(FROM_UNIXTIME(send_time),'%Y%m%d') = DATE_FORMAT(NOW(),'%Y%m%d')";
		$total_rebate_num=M("user_rebate_send_log")->field("send_money as money,send_num AS total_rebate")->where($map_today)->find();
		//echo $this->points_db->getlastsql();
		//print_r($total_rebate);
		//exit;
		$days = (isset($_GET['days'])) ? (int) $_GET['days'] : 7;
		$sqlmap = array();
		switch ($days) {
			case '7':
				$sqlmap['addtime'] = array("GT", NOW_TIME - 86400 * 7);
				$start_time = NOW_TIME - 86400 * 6;
				$end_time = NOW_TIME;
				break;
			case '30':
				$sqlmap['addtime'] = array("GT", NOW_TIME - 86400 * 30);
				$start_time = NOW_TIME - 86400 * 29;
				$end_time = NOW_TIME;
				break;
			default:
				$create_time = array();				
				$start_time = strtotime($_GET['start_time'].' 00:00:00');
				$end_time = strtotime($_GET['end_time'].' 23:59:59');
				$create_time[] = array("GT", $start_time);
				$create_time[] = array("LT", $end_time);
				$create_time[] = 'AND';
				$sqlmap['addtime'] = $create_time;
				$days = ceil(($end_time - $start_time) / 86400);
				break;
		}
		for ($i=0; $i < $days; $i++) { 
			$_time = NOW_TIME - 86400 * $i;
			$sell_list[mdate($_time, 'Y-m-d')] = $this->public_daysell(mdate($_time, 'Ymd'));
			$series_real_amount[] = round($sell_list[mdate($_time, 'Y-m-d')]['real_amount'],2);
			$series_order_effect[] = intval($sell_list[mdate($_time, 'Y-m-d')]['order_effect']);
		}
		//print_r($series_real_amount);
		$series[] = array('name' => '赠送金额', 'data' => array_reverse($series_real_amount), 'tooltip' => array('valueSuffix' => ' 元'));
		$series[] = array('name' => '赠送权', 'data' => array_reverse($series_order_effect), 'tooltip' => array('valueSuffix' => ' 个'));
		$sell_list = array_reverse($sell_list, TRUE);
		$sell_days = array_keys($sell_list);
		/* 引入后台模板 */
		include $this->admin_tpl('Rebate/oldlist');
	}
	
	
    public function yesterday() {
		$return_num=M("user")->sum("rebate_num");
		$return_money=M("user_moneylog")->where("type=9 and msg='赠送发放'")->sum("money");
		$map_today['sell_uid'] = array("neq",0);
		$amount_all = model('order')->where($map_today)->sum('real_amount');
		$amount_all=$amount_all==0?"0.00":$amount_all;
		$start=strtotime(date("Y/m/d", strtotime('-1 day'))." 00:00:01");
		$end=strtotime(date("Y/m/d", strtotime('-1 day'))." 23:59:59"); 
		$map_today['create_time'] =array('between',$start.','.$end);
		$map_today['sell_uid'] = array("neq",0);
		$amount_yesterday = model('order')->where($map_today)->sum('real_amount');
		$amount_yesterday=$amount_yesterday==0?"0.00":$amount_yesterday;
		include $this->admin_tpl('Rebate/yesterday');
	}
	public function selloldlist() {
		$map_today = array();
		$map=array();
		/* 今日销售情况 */
		$map_today['_string'] = "DATE_FORMAT(FROM_UNIXTIME(send_time),'%Y%m%d') = DATE_FORMAT(NOW(),'%Y%m%d')";
		$total_rebate = M("user_sell_rebate_send_log")->field("sum(send_all_money) as total_rebate_money,send_user AS total_rebate")->where($map_today)->find();
		$map_today = array();
		$map_today['_string'] = "DATE_FORMAT(FROM_UNIXTIME(send_time),'%Y%m%d') = DATE_FORMAT(NOW(),'%Y%m%d')";
		$total_rebate_num=M("user_sell_rebate_send_log")->field("send_money as money,send_num AS total_rebate")->where($map_today)->find();
		//echo $this->points_db->getlastsql();
		//print_r($total_rebate);
		//exit;
		$days = (isset($_GET['days'])) ? (int) $_GET['days'] : 7;
		$sqlmap = array();
		switch ($days) {
			case '7':
				$sqlmap['addtime'] = array("GT", NOW_TIME - 86400 * 7);
				$start_time = NOW_TIME - 86400 * 6;
				$end_time = NOW_TIME;
				break;
			case '30':
				$sqlmap['addtime'] = array("GT", NOW_TIME - 86400 * 30);
				$start_time = NOW_TIME - 86400 * 29;
				$end_time = NOW_TIME;
				break;
			default:
				$create_time = array();				
				$start_time = strtotime($_GET['start_time'].' 00:00:00');
				$end_time = strtotime($_GET['end_time'].' 23:59:59');
				$create_time[] = array("GT", $start_time);
				$create_time[] = array("LT", $end_time);
				$create_time[] = 'AND';
				$sqlmap['addtime'] = $create_time;
				$days = ceil(($end_time - $start_time) / 86400);
				break;
		}
		for ($i=0; $i < $days; $i++) { 
			$_time = NOW_TIME - 86400 * $i;
			$sell_list[mdate($_time, 'Y-m-d')] = $this->public_daysellb(mdate($_time, 'Ymd'));
			$series_real_amount[] = round($sell_list[mdate($_time, 'Y-m-d')]['real_amount'],2);
			$series_order_effect[] = intval($sell_list[mdate($_time, 'Y-m-d')]['order_effect']);
		}
		//print_r($series_real_amount);
		$series[] = array('name' => '赠送金额', 'data' => array_reverse($series_real_amount), 'tooltip' => array('valueSuffix' => ' 元'));
		$series[] = array('name' => '赠送权', 'data' => array_reverse($series_order_effect), 'tooltip' => array('valueSuffix' => ' 个'));
		$sell_list = array_reverse($sell_list, TRUE);
		$sell_days = array_keys($sell_list);
		/* 引入后台模板 */
		include $this->admin_tpl('Rebate/selloldlist');
	}
	public function return_money() {


		$is_fafang_time=strtotime(date('Y-m-d 00:00:01',time()));
		$is_fafang=M("user_rebate_log")->where("addtime>".$is_fafang_time)->count();
		
		if($is_fafang>0){
			showmessage('今天已经进行过赠送了,请不要重新发放');
			exit;
		}


		$Rebate=M("user_rebate");
		$Rebatelog=M("user_rebate_log");
		$User=M("user");
		$return_type=$_POST["return_type"];
		if($return_type==1){
			$money=$_POST["return_money"];
		}else{
			$money=$_POST["return_money2"];
		}
		$user_num=0;
		$all_num=0;//人数
		$Rebate->startTrans();
		$all_list=$Rebate->where("status=0")->order("id asc")->select();
		//G('begin');
		foreach($all_list as $key=>$val){
			if($u[$val["uid"]]["all"]==""){
                    $u[$val["uid"]]["all"]=$Rebate->where("status=0 and uid=".$val["uid"])->order("id asc")->count();
                }
                $Rebate_arr["id"]=$val["id"];
                $Rebate_arr["return_money"]=array('exp','return_money+'.$money);
                $up_rebate_money[]=$Rebate_arr;
           
                if($all_return_arr[$val["uid"]]==""){
                    $all_return_arr[$val["uid"]]=$Rebate->where("uid=".$val["uid"])->sum("return_money");
                }
                $all_return_arr[$val["uid"]]+=$money;
                $all_return=$all_return_arr[$val["uid"]];
                $all_num_over=floor($all_return/1000);
                if($now_num_arr[$val["uid"]]==""){
                    $now_num_arr[$val["uid"]]=$Rebate->where("status=1 and uid=".$val["uid"])->count();
                }
                $now_num=$now_num_arr[$val["uid"]];
                if($all_num_over>0 and $now_num<$all_num_over){
                    $end_data["id"]=$val["id"];
                    $end_data["status"]=1;
                    $end_data["end_time"]=time();
                    $end_status[]=$end_data;
                    $now_num_arr[$val["uid"]]+=1;//设置一个赠送权为已经发放满1000元了
                    
                }
                
                $data["uid"]=$val["uid"];
                $data["return_type"]=$return_type;
                $data["money"]=$money;
                $data["rid"]=$val["id"];
                $data["addtime"]=time();
                $u[$val["uid"]]["num"]+=1;
                
                //更新账户资金 + 更新账户积分
                $where['id']=$val["uid"];
                $where['user_money']=array('exp','user_money+'.$money);
                $where['pay_points']=array('exp','pay_points+'.$money);
                $save_money_arr[]=$where;
                if($u[$val["uid"]]["num"]==$u[$val["uid"]]["all"]){
                    $points_info=model('user')->find($val["uid"]);
                    $points['user_id']=$val["uid"];
                    $points['info']="赠送发放：".$money."元 X ".$u[$val["uid"]]["all"]."个赠送权";
                    $points['descript']="赠送发放";
                    $points['pay_points']=$money*$u[$val["uid"]]["all"];
                    $points['time']=time();
                    $points['type']=3;
                    $points['user_points']=$points_info["pay_points"]+$money*$u[$val["uid"]]["all"];
                    $pointslog[]=$points;
                    $user_money['user_id'] = $val["uid"];
                    $user_money['money'] = $money*$u[$val["uid"]]["all"];
                    $user_money['msg'] = "赠送发放";
                    $user_money['info']="赠送发放：".$money."元 X ".$u[$val["uid"]]["all"]."个赠送权";
                    $user_money['dateline'] = NOW_TIME;
                    $user_money['type'] = 9;
                    $user_money['user_money'] = $points_info["user_money"]+$money*$u[$val["uid"]]["all"];
                    $user_money['freeze_money'] = $points_info["freeze_money"];
                    $user_moneylog[]=$user_money;
                    $user_num+=1;
                }
                $all_num+=1;
                $logdata[]=$data;
                unset($end_data);
                unset($Rebate_arr);
                unset($where);
                unset($points);
                unset($data);
		}
		if(count($end_status)>0){
			foreach($end_status as $vala){
				//$Rebate->create($val);
				$is_status=$Rebate->save($vala);
				if($is_status === false ){$is_status=false;continue;}
			}
		}else{
			$is_status=true;	
		}
		if(count($up_rebate_money)>0){
			foreach($up_rebate_money as $valb){
				//$Rebate->create($val);
				$is_update_rebate=$Rebate->save($valb);
				if($is_update_rebate === false ){$is_update_rebate=false;continue;}
			}
		}else{
			$is_update_rebate=true;	
		}
		if(count($save_money_arr)>0){
			foreach($save_money_arr as $valc){
				//$User->create($val);
				$update_points=$User->save($valc);
				if($update_points === false ){$update_points=false;continue;}
			}
		}else{
			$update_points=true;	
		}
		
		$is_save_log=$Rebatelog->addAll($logdata);//更新发放日志
		$is_save_pointslog=model('User_pointslog')->addAll($pointslog);//更新积分记录
		$is_save_user_moneylog=model('User_moneylog')->addAll($user_moneylog);//更新积分记录
		/*echo "状态".$is_status."<br>";
		echo "资金".$is_update_rebate."<br>";
		echo "账户".$update_points."<br>";
		echo "日志A".$is_save_log."<br>";
		echo "积分B".$is_save_pointslog."<br>";
		echo "积分C".$is_save_user_moneylog."<br>";
		G('end');
		echo G('begin','end').'s';
		echo "<pre>";
		exit;*/
		if ($is_status!==false and $is_update_rebate!==false and $update_points!==false and $$is_save_log!==false and $is_save_pointslog!==false and $is_save_user_moneylog!==false){ 
			$lastsave["lasttime"]=time();
			$is_last=M("user_rebate_set")->where("id=1")->save($lastsave);
			if($is_last!==false){
				$Rebate->commit();
				showmessage( '本次共成功赠送积分：'.($money*$all_num)."元，共".$all_num."个赠送权限"."，涉及".$user_num."人");	
			}else{
				 $Rebate->rollback(); 
				 showmessage('红利发放失败,错误代码021');	
			}
		   
		}else{
			$Rebate->rollback(); 
			showmessage('赠送积分失败,错误代码020');
		}
	}
	
	
	public function old() {
		if(IS_POST){
			$points_type=C("POINTS_TYPE");
			$sqlmap = array();
			$order = array();
			//排序
			$_order=isset($_POST['order']) ? ($_POST['order']) : NULL;
			$_sort=isset($_POST['sort']) ? ($_POST['sort']) : NULL;
			if($_order && $_sort){
				$order[$_sort] = $_order;
			}else{
				$order['id'] = 'desc';
			}
			
			if ($_GET['keyword']) {
				$map = array();
				$map['username'] = array('LIKE',"%".trim($_GET['keyword'])."%");
				$ids = model('user')->where($map)->getField('id',TRUE);
				$sqlmap['user_id'] = array('IN',$ids);
			}
			if($_GET["start"]!="" or $_GET["end"]!=""){
				$start = strtotime($_GET['start'].' 00:00:00');
				$end = strtotime($_GET['end'].' 23:59:59');
				$sqlmap['time'] =array('between',$start.','.$end);
			}
			$sqlmap['type'] =array('eq',3);
			$pagenum=isset($_POST['page']) ? intval($_POST['page']) : 1;
			$rowsnum=isset($_POST['rows']) && (int)($_POST['rows']) != 0 ? intval($_POST['rows']) : PAGE_SIZE;
			$data['total'] =M("user_pointslog")->where($sqlmap)->count();	//计算总数 
			$data['rows'] = M("user_pointslog")->where($sqlmap)->limit(($pagenum-1)*$rowsnum.','.$rowsnum)->order($order)->select();
			foreach ($data['rows'] as $key => $value) {
				$data['rows'][$key]['type'] = $points_type[$value["type"]];
				//$data['rows'][$key]['address'] = $value["province"].$value["city"].$value["hometown"].$value["address"];
				//$data['rows'][$key]['return_type']=$data['rows'][$key]['return_type']==1?"固定分红":"百分比分红";
				$data['rows'][$key]['username']=get_nickname($data['rows'][$key]['user_id']);
			}
			if (!$data['rows']) $data['rows']=array();
			echo json_encode($data);
		}else{
			include $this->admin_tpl('Rebate/old');
		}
	}
	
	
	public function public_dayselllist() {
		$days = (isset($_GET['days'])) ? (int) $_GET['days'] : 7;
		$sqlmap = array();
		$sqlmap['order_status'] = array("LT", 3);		
		switch ($days) {
			case '7':
				$sqlmap['addtime'] = array("GT", NOW_TIME - 86400 * 7);
				break;
			case '30':
				$sqlmap['addtime'] = array("GT", NOW_TIME - 86400 * 30);
				break;
			default:
				$create_time = array();
				$start_time = strtotime($_GET['start_time'].' 00:00:00');
				$end_time = strtotime($_GET['end_time'].' 23:59:59');
				$create_time[] = array("GT", $start_time);
				$create_time[] = array("LT", $end_time);
				$create_time[] = 'AND';
				$sqlmap['addtime'] = $create_time;
				$days = ceil(($end_time - $start_time) / 86400);
				break;
		}
		$si = (PAGE - 1) * PAGE_SIZE;
		$ei = $si + PAGE_SIZE;
		if($ei > $days) $ei = $days;

		for ($i=$si; $i < $ei; $i++) { 
			$_time = NOW_TIME - 86400 * $i;		
			$sell_list[mdate($_time, 'Y-m-d')] = $this->public_daysell(mdate($_time, 'Ymd'));
			$series_real_amount[] = intval($sell_list[mdate($_time, 'Y-m-d')]['real_amount']);
			$series_order_effect[] = intval($sell_list[mdate($_time, 'Y-m-d')]['order_effect']);
		}
		$pages = pages($days, PAGE_SIZE);
		echo json_encode(array('lists' => $sell_list, 'pages' => $pages));			
	}
		public function public_dayselllistb() {
		$days = (isset($_GET['days'])) ? (int) $_GET['days'] : 7;
		$sqlmap = array();
		$sqlmap['order_status'] = array("LT", 3);		
		switch ($days) {
			case '7':
				$sqlmap['addtime'] = array("GT", NOW_TIME - 86400 * 7);
				break;
			case '30':
				$sqlmap['addtime'] = array("GT", NOW_TIME - 86400 * 30);
				break;
			default:
				$create_time = array();
				$start_time = strtotime($_GET['start_time'].' 00:00:00');
				$end_time = strtotime($_GET['end_time'].' 23:59:59');
				$create_time[] = array("GT", $start_time);
				$create_time[] = array("LT", $end_time);
				$create_time[] = 'AND';
				$sqlmap['addtime'] = $create_time;
				$days = ceil(($end_time - $start_time) / 86400);
				break;
		}
		$si = (PAGE - 1) * PAGE_SIZE;
		$ei = $si + PAGE_SIZE;
		if($ei > $days) $ei = $days;

		for ($i=$si; $i < $ei; $i++) { 
			$_time = NOW_TIME - 86400 * $i;		
			$sell_list[mdate($_time, 'Y-m-d')] = $this->public_daysellb(mdate($_time, 'Ymd'));
			$series_real_amount[] = intval($sell_list[mdate($_time, 'Y-m-d')]['real_amount']);
			$series_order_effect[] = intval($sell_list[mdate($_time, 'Y-m-d')]['order_effect']);
		}
		$pages = pages($days, PAGE_SIZE);
		echo json_encode(array('lists' => $sell_list, 'pages' => $pages));			
	}
	/* 获取指定日期的销售情况（$time 格式为：20141231） */
	private function public_daysell($time) {
		$sqlmap = array();
		$sqlmap['_string'] = "DATE_FORMAT(FROM_UNIXTIME(send_time),'%Y%m%d') = '".$time."'";
		$sell_day = M("user_rebate_send_log")->field("sum(send_all_money) AS real_amount, send_num AS order_effect,send_money as user_cust_transaction")->where($sqlmap)->find();
		$sell_day['real_amount'] = sprintf('%.2f', $sell_day['real_amount']);
		unset($sqlmap['order_status']);
		return $sell_day;
	}

	/* 获取指定日期的销售情况（$time 格式为：20141231） */
	private function public_daysellb($time) {
		$sqlmap = array();
		$sqlmap['_string'] = "DATE_FORMAT(FROM_UNIXTIME(send_time),'%Y%m%d') = '".$time."'";
		$sell_day = M("user_sell_rebate_send_log")->field("sum(send_all_money) AS real_amount, send_num AS order_effect,send_money as user_cust_transaction")->where($sqlmap)->find();
		$sell_day['real_amount'] = sprintf('%.2f', $sell_day['real_amount']);
		unset($sqlmap['order_status']);
		return $sell_day;
	}
}
